
// import store from '../store'
import request from '../utils/request.js'
export const allChannelListApi = () => {
  return request(
    {
      url: '/v1_0/channels'
    }
  )
}

export const LoginApi = ({ mobile, code }) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile: mobile,
      code: code
    }
  })
}

export const userChannelAPI = () => {
  return request({
    url: '/v1_0/user/channels'
    // headers: {
    //   Authorization: 'Bearer ' + store.state.token
    // }
  })
}

export const articlesListAPI = (channelId, timestamp) => {
  return request({
    url: '/v1_0/articles',
    method: 'GET',
    params: {
      channel_id: channelId,
      timestamp: timestamp || (new Date()).getTime()
    }
  })
}

// 不感兴趣
export const actionDisLikeApi = ({ target }) => {
  return request({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    data: {
      target: target
    }
    // headers: {
    //   Authorization: 'Bearer ' + store.state.token
    // }
  })
}

// 反馈垃圾内容
export const articleReportsAPI = ({ target, type, remark }) => {
  return request({
    url: '/v1_0/article/reports',
    method: 'POST',
    data: {
      target: target,
      type: type,
      remark: remark
    }
    // headers: {
    //   Authorization: 'Bearer ' + store.state.token
    // }
  })
}

// 频道 - 更新已选
export const updateChannelAPI = ({ channels }) => {
  return request({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
      channels: channels
    }
  })
}
// 获取联想列表
export const suggestListAPI = ({ q }) => {
  return request({
    url: '/v1_0/suggestion',
    method: 'GET',
    params: {
      q
    }
  })
}
// 文章搜索结果列表
export const searchResultListAPI = ({ q, page }) => {
  return request({
    url: '/v1_0/search',
    method: 'GET',
    params: {
      q: q,
      page: page
    }
  })
}
// 文章详情数据渲染
export const articleDetailAPI = (id) => {
  return request({
    url: `/v1_0/articles/${id}`,
    method: 'GET'
    // params: {
    //   id
    // }
  })
}
// 关注接口
export const followedUserAPI = ({ target }) => {
  return request({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target: target
    }
  })
}
// 取关接口
export const unFollowedUserAPI = ({ uid }) => {
  return request({
    url: `/v1_0/user/followings/${uid}`,
    method: 'DELETE'

  })
}
// 点赞
export const articleLikeAPI = ({ target }) => {
  return request({
    url: '/v1_0/article/likings',
    method: 'POST',
    data: {
      target: target
    }
  })
}
// 取消点赞
export const articleDisLikeAPI = ({ target }) => {
  return request({
    url: `/v1_0/article/likings/${target}`,
    method: 'DELETE'

  })
}
// 评论 - 获取列表
// offset第一页时, 不用在params携带(axios发现值为null会自动忽略此参数)
export const commentListAPI = ({ target, limit = 10, offset = null }) => {
  return request({
    url: '/v1_0/comments',
    method: 'GET',
    params: {
      type: 'a',
      source: target,
      limit: limit,
      offset: offset
    }
  })
}
// 评论 - 喜欢
export const commentLikingAPI = ({ comId }) => {
  return request({
    url: '/v1_0/comment/likings',
    method: 'POST',
    data: {
      target: comId
    }
  })
}
// 评论-取消喜欢
export const commentDisLikingAPI = ({ comId }) => {
  return request({
    url: `/v1_0/comment/likings/${comId}`,
    method: 'DELETE'
  })
}
// 评论发布
export const sendCommentAPI = ({ artId, content }) => {
  return request({
    url: '/v1_0/comments',
    method: 'POST',
    data: {
      target: artId,
      content: content
    }
  })
}
// 用户信息
export const userInfoAPI = () => {
  return request({
    url: '/v1_0/user'
  })
}
// 获取用户资料
export const userProfileAPI = () => {
  return request({
    url: '/v1_0/user/profile'
  })
}
// 编辑用户头像
export const updatePhotoAPI = (formObj) => {
  return request({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data: formObj
  })
}
// 用户 - 更新资料
export const updateProfileAPI = ({ birthday, userName }) => {
  return request({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data: {
      birthday: birthday,
      name: userName
    }
  })
}
